export default {
    namespaced: true,
    state:{
         productData: [] 
    },
    mutations:{
        SET_PRODUCT_DATA(state,payload){
            state.productData = payload
        },
        DECREASE_INVENTORY(state,payload){
            let target = state.productData.find(item =>item.id === payload)
            if (target) {
                target.inventory--
                }
        },
        INCREASE_INVENTORY(state,payload){
            let target = state.productData.find(item => item.id === payload.id)
            if (target) {
                target.inventory++
                }
        }
    },
    actions:{
        async FETCH_PRODUCT(context){
            let res = await fetch('/api/data/index.json').then(body => body.json());
            console.log(res)
            context.commit('SET_PRODUCT_DATA',res.data)
        }
    },
    getters:{},
}